# -*- coding: utf-8 -*-
# flake8: noqa
from qiniu import Auth, put_file, etag
import qiniu.config
def qiniuimg(key, localfile):
    #需要填写你的 Access Key 和 Secret Key
    access_key = 'ONE4qE-ZHov36aTj_5tXw57k1uHcaJG7Uf2j2Lhx'
    secret_key = 'dh7MYkRjHN0ThT9OQrqo0-NwQuUNE0p55kniL5lT'
    #构建鉴权对象
    q = Auth(access_key, secret_key)
    #要上传的空间
    bucket_name = 'ihome-py41'
    #上传后保存的文件名
    # key = 'my-python-logo.png'
    #生成上传 Token，可以指定过期时间等
    token = q.upload_token(bucket_name, key, 3600)
    #要上传文件的本地路径
    # localfile = './sync/bbb.jpg'
    ret, info = put_file(token, key, localfile)
    # print(info)
    # print(ret)
    assert ret['key'] == key
    assert ret['hash'] == etag(localfile)
    return ret['key']